/**
 * Created by zycool on 2016/9/1.
 * 管道基础数据 - 系统设置
 */


;(function ($, window, document, undefined) {

    /*** 场站阀室 start ***/
    // 场站阀室名称
    var $room_name = $('#JQ_room_name');
    // 场站阀室代号
    var $room_code = $('#JQ_room_code');
    // 任务状态
    var $room_task_state = $('#JQ_room_task_state').select3({
        search: false,
        data: [
            {id: '20', text: '已发布'},
            {id: '03', text: '未发布'}
        ]
    });
    // 状态
    var $room_work_state = $('#JQ_room_work_state').select3({
        search: false,
        data: [
            {id: '0', text: '启用'},
            {id: '1', text: '停用'}
        ]
    });
    // 场站阀室列表
    var $room_table = $('#JQ_datatable_room').checkbox3();
    // 场站阀室表单
    var $room_form = $('#JQ_action_room_form');

    /***---------- 编辑 ----------***/
    var $room_name_edit = $('#JQ_room_name_edit');
    var $room_code_edit = $('#JQ_room_code_edit');
    // 场站阀室类型
    var $room_type_edit = $('#JQ_room_type_edit').select3({search:false});
    /*** 场站阀室 end ***/


    /*** 管道 start ***/
    // 管道名称
    var $pipe_name = $('#JQ_pipe_name');
    // 管道代号
    var $pipe_code = $('#JQ_pipe_code');
    // 任务状态
    var $pipe_task_state = $('#JQ_pipe_task_state').select3({
        search: false,
        data: [
            {id: '20', text: '已发布'},
            {id: '03', text: '未发布'}
        ]
    });
    // 状态
    var $pipe_work_state = $('#JQ_pipe_work_state').select3({
        search: false,
        data: [
            {id: '0', text: '启用'},
            {id: '1', text: '停用'}
        ]
    });
    // 管道列表
    var $pipe_table = $('#JQ_datatable_pipe').checkbox3();
    // 管道表单
    var $pipe_form = $('#JQ_action_pipe_form');

    /***---------- 编辑 ----------***/
    var $pipe_name_edit = $('#JQ_pipe_name_edit');
    var $pipe_code_edit = $('#JQ_pipe_code_edit');
    // 场站阀室下拉列表
    var $pipe_room_select;
    // 场站阀室添加表格
    var $pipe_room_table = $('#JQ_pipe_room_table');
    /*** 管道 end ***/

    /*** 管段 start ***/
    // 管道名称
    var $segment_pipe = $('#JQ_pipeline').select3({
        serverPath: DyyBase.url_piping()
    });
    // 管段名称
    var $segment_name = $('#JQ_segment_name');
    // 管段代号
    var $segment_code = $('#JQ_segment_code');
    // 任务状态
    var $segment_task_state = $('#JQ_segment_task_state').select3({
        search: false,
        data: [
            {id: '20', text: '已发布'},
            {id: '03', text: '未发布'}
        ]
    });
    // 状态
    var $segment_work_state = $('#JQ_segment_work_state').select3({
        search: false,
        data: [
            {id: '0', text: '启用'},
            {id: '1', text: '停用'}
        ]
    });
    // 管段列表
    var $segment_table = $('#JQ_datatable_segment').checkbox3();
    // 分段标识列表
    var $pipe_sign_room = $('#JQ_pipe_sign_room');

    /***---------- 编辑 ----------***/
    // 管道
    var $segment_pipe_edit = $('#JQ_segment_pipe_name').select3({
        serverPath: DyyBase.url_piping(),
        data: $segment_pipe.val('store')
    });
    // 管段名称
    var $segment_name_edit = $('#JQ_segment_name_edit');
    // 管段代号
    var $segment_code_edit = $('#JQ_segment_code_edit');
    // 起点
    var $segment_begin = $('#JQ_segment_begin_room').select3({
        server: true,
        param:{pipeLineId:$segment_pipe_edit}
    });
    // 终点
    var $segment_end = $('#JQ_segment_end_room').select3({
        server: true,
        param:{pipeLineId:$segment_pipe_edit,beginSignId:$segment_begin}
    });
    $segment_pipe_edit.element.on('select',function(e,v){
        var id = v || $segment_pipe_edit.val();
        if(id){
            // 起点 & 终点
            DyyBase.ajax(DyyBase.url_pipe_pos(), {pipeLineId:id}, function(dataset){
                var begin = DyyBase.getPos(dataset,'begin');
                var end = DyyBase.getPos(dataset,'end');
                $segment_begin.asset(begin);
                $segment_end.asset(end);
            },{async:false});
        }
    });
    // 管段表单
    var $segment_form = $('#JQ_action_segment_form');
    /*** 管段 end ***/


    /*** 筛选对象 start ***/
    var filter = {
        // 场站阀室
        getRoomFilter: function (data) {
            var filter = {};
            // 分页参数
            if (data) {
                if (data.start == 0) {
                    filter['jsonBean.pageNum'] = 1;
                } else {
                    filter['jsonBean.pageNum'] = data.start / 10 + 1;
                }
                filter['jsonBean.pageCount'] = data.length;
            }
            // 查询参数
            filter.valveRoomName = function () {
                var v = $room_name.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            filter.valveRoomAbridge = function () {
                var v = $room_code.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            filter.taskStatus = function () {
                var v = $room_task_state.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            filter.status = function () {
                var v = $room_work_state.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            return filter;
        },
        // 管道
        getPipeFilter: function (data) {
            var filter = {};
            // 分页参数
            if (data) {
                if (data.start == 0) {
                    filter['jsonBean.pageNum'] = 1;
                } else {
                    filter['jsonBean.pageNum'] = data.start / 10 + 1;
                }
                filter['jsonBean.pageCount'] = data.length;
            }
            // 查询参数
            filter.lineName = function () {
                var v = $pipe_name.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            filter.lineAbridge = function () {
                var v = $pipe_code.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            filter.taskStatus = function () {
                var v = $pipe_task_state.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            filter.status = function () {
                var v = $pipe_work_state.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            return filter;
        },
        // 管段 - 查询
        getSegmentFilter: function (data) {
            var filter = {};
            // 分页参数
            if (data) {
                if (data.start == 0) {
                    filter['jsonBean.pageNum'] = 1;
                } else {
                    filter['jsonBean.pageNum'] = data.start / 10 + 1;
                }
                filter['jsonBean.pageCount'] = data.length;
            }
            // 查询参数
            filter.lineNameId = function () {
                var v = $segment_pipe.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            filter.segmentName = function () {
                var v = $segment_name.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            filter.segmentAbridge = function () {
                var v = $segment_code.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            filter.taskStatus = function () {
                var v = $segment_task_state.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            filter.status = function () {
                var v = $segment_work_state.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            return filter;
        },
        // 管段 - 新建
        getSegmentFilter2: function () {
            var filter = {};
            filter.mode = true;
            filter.id = function () {
                var v = $('#JQ_segment_id').val();
                if (v) {
                    return v;
                }
                return '';
            }();
            filter.lineNameId = function () {
                var v = $segment_pipe_edit.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            filter.segmentName = function () {
                var v = $segment_name_edit.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            filter.segmentAbridge = function () {
                var v = $segment_code_edit.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            filter.fromPipeValveroomId = function () {
                var v = $segment_begin.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            filter.toPipeValveroomId = function () {
                var v = $segment_end.val();
                if (v) {
                    return v;
                }
                return '';
            }();
            return filter;
        },
        // 公司名称 ID 数组
        getRoomIds: function(){
            var arr = [];
            var $chks = $room_table.find('i.zy-checkbox');
            if($chks.length > 0){
                $chks.each(function(){
                    var $this = $(this);
                    if($this.hasClass('active')){
                        arr.push({name:'ids',value:$this.attr('data-id')});
                    }
                });
            }
            return arr;
        },
        // 管道 ID 数组
        getPipeIds: function(){
            var arr = [];
            var $chks = $pipe_table.find('i.zy-checkbox');
            if($chks.length > 0){
                $chks.each(function(){
                    var $this = $(this);
                    if($this.hasClass('active')){
                        arr.push({name:'ids',value:$this.attr('data-id')});
                    }
                });
            }
            return arr;
        },
        // 管段 ID 数组
        getSegmentIds: function(){
            var arr = [];
            var $chks = $segment_table.find('i.zy-checkbox');
            if($chks.length > 0){
                $chks.each(function(){
                    var $this = $(this);
                    if($this.hasClass('active')){
                        arr.push({name:'ids',value:$this.attr('data-id')});
                    }
                });
            }
            return arr;
        },
        // 新建 场站阀室
        getRoom: function(){
            var filter = {};
            filter.mode = true;
            filter.id = $('#JQ_room_id').val();
            filter.valveRoomName = function(){
                var v = $room_name_edit.val();
                if(v){
                    return v;
                }
                return '';
            }();
            filter.valveRoomAbridge = function(){
                var v = $room_code_edit.val();
                if(v){
                    return v;
                }
                return '';
            }();
            filter.valveRoomType = function(){
                var v = $room_type_edit.val();
                if(v){
                    return v;
                }
                return '';
            }();
            return filter;
        },
        // 新建 管道
        getPipe: function(){
            var data = {};
            data.mode = true;
            data.id = function(){
                var v = $('#JQ_pipe_id').val();
                if(v){
                    return v;
                }
                return '';
            }();
            data.lineName = function(){
                var v = $pipe_name_edit.val();
                if(v){
                    return v;
                }
                return '';
            }();
            data.lineAbridge = function(){
                var v = $pipe_code_edit.val();
                if(v){
                    return v;
                }
                return '';
            }();
            data.vrIds = function(){
                var $tr = $pipe_room_table.find('tr');
                var arr = [];
                if($tr.length > 0){
                    $tr.each(function(){
                        var $this = $(this);
                        var id = $this.attr('data-id');
                        arr.push(id);
                    });
                }
                if(arr.length < 2){
                    $pipe_room_select.element.TIP({content:'沿线场站阀室必须有2个及以上!'});
                    data.mode = false;
                }
                return arr;
            }();
            return data;
        }
    };
    /*** 筛选对象 end ***/

    /*** 加载列表 start ***/
    var DTROOM, DTPIPE, DTSEGMENT;

    function loadRoom(){
        if(DTROOM){
            DTROOM.draw();
        }else{
            DTROOM = $room_table.DataTable({
                'language': {
                    'paginate': {
                        'next': '下一页',
                        'previous': '上一页'
                    },
                    'info': '本次检索共 _TOTAL_ 条，每页显示 10 条，共 _PAGES_ 页',
                    'zeroRecords': DyyBase.table_empty(),
                    'infoEmpty': ''
                },
                'autoWidth': false,
                'order': [],
                'serverSide': true,
                'ordering': false,
                'processing': false,
                'searching': false,
                'lengthChange': false,
                'ajax': function (data, callback) {
                    var param = filter.getRoomFilter(data);
                    DyyBase.ajax(sysApi.url_room_list(), param, function (dataset) {
                        var returnData = {};
                        returnData.draw = data.draw;
                        returnData.recordsTotal = dataset.result.total;
                        returnData.recordsFiltered = dataset.result.total;
                        returnData.data = DyyBase.clearNull(dataset.result.list);
                        callback(returnData);
                    });
                },
                'drawCallback': function () {
                },
                'columns': [
                    {
                        data: 'id', render: function (data) {
                        return '<i class="zy-checkbox" data-id="' + data + '" title="选中"></i>';
                    }
                    },
                    {
                        data: 'showName', render: function (data) {
                        return '<span title="' + data + '">' + data + '</span>';
                    }
                    },
                    {
                        data: 'abridge', render: function (data) {
                        return '<span title="' + data + '">' + data + '</span>';
                    }
                    },
                    {
                        data: 'type', render: function (data) {
                        return '<span title="' + data + '">' + data + '</span>';
                    }
                    },
                    {
                        data: 'dataStated', render: function (data) {
                        if(data == '20'){
                            return '<span title="' + data + '">已发布</span>';
                        }else{
                            return '<span title="' + data + '">未发布</span>';
                        }
                    }
                    },
                    {
                        data: 'state', render: function (data,type,row) {
                        if(data == '0'){
                            return '<i data-id="'+row.id+'" data-state="'+data+'" class="zy-switch-sys"></i>';
                        }else{
                            return '<i data-id="'+row.id+'" data-state="'+data+'" class="zy-switch-sys off"></i>';
                        }
                    }
                    },
                    {
                        data: 'id', render: function (data) {
                        return '<i data-id="'+data+'" class="zy-record-add-icon" title="编辑"></i>&nbsp;&nbsp;&nbsp;<i data-id="'+data+'" class="zy-list-icon-delete" title="删除"></i>';
                    }
                    }
                ]
            });
        }
    }
    loadRoom();

    // 加载管道数据
    function loadPipe(){
        if(DTPIPE){
            DTPIPE.draw();
            $pipe_room_select.reload();
        }else{
            DTPIPE = $pipe_table.DataTable({
                'language': {
                    'paginate': {
                        'next': '下一页',
                        'previous': '上一页'
                    },
                    'info': '本次检索共 _TOTAL_ 条，每页显示 10 条，共 _PAGES_ 页',
                    'zeroRecords': DyyBase.table_empty(),
                    'infoEmpty': ''
                },
                'autoWidth': false,
                'order': [],
                'serverSide': true,
                'pageLength': 10,
                'ordering': false,
                'processing': false,
                'searching': false,
                'lengthChange': false,
                'ajax': function (data, callback) {
                    var param = filter.getPipeFilter(data);
                    DyyBase.ajax(sysApi.url_pipe_list(), param, function (dataset) {
                        var returnData = {};
                        returnData.draw = data.draw;
                        returnData.recordsTotal = dataset.result.total;
                        returnData.recordsFiltered = dataset.result.total;
                        returnData.data = DyyBase.clearNull(dataset.result.list);
                        callback(returnData);
                    });
                },
                'drawCallback': function () {
                },
                'columns': [
                    {
                        data: 'id', render: function (data) {
                        return '<i class="zy-checkbox" data-id="' + data + '" title="选中"></i>';
                    }
                    },
                    {
                        data: 'showName', render: function (data) {
                        return '<span title="' + data + '">' + data + '</span>';
                    }
                    },
                    {
                        data: 'abridge', render: function (data) {
                        return '<span title="' + data + '">' + data + '</span>';
                    }
                    },
                    {
                        data: 'dataStated', render: function (data) {
                        if(data == '20'){
                            return '<span title="' + data + '">已发布</span>';
                        }else{
                            return '<span title="' + data + '">未发布</span>';
                        }
                    }
                    },
                    {
                        data: 'state', render: function (data,type,row) {
                        if(data == '1'){
                            return '<i data-id="'+row.id+'" data-state="'+data+'" class="zy-switch-sys off"></i>';
                        }else{
                            return '<i data-id="'+row.id+'" data-state="'+data+'" class="zy-switch-sys"></i>';
                        }
                    }
                    },
                    {
                        data: 'id', render: function (data) {
                        return '<i data-id="'+data+'" class="zy-edit-icon-txt">编辑</i>';
                    }
                    },
                    {
                        data: 'id', render: function (data) {
                        return '<i data-id="'+data+'" class="zy-view-icon" title="编辑"></i>';
                    }
                    },
                    {
                        data: 'id', render: function (data,type,row) {
                        return '<i data-id="'+data+'" class="zy-record-add-icon" title="编辑"></i>&nbsp;&nbsp;&nbsp;<i data-id="'+data+'" data-status="'+row.dataStated+'" class="zy-list-icon-delete" title="删除"></i>';
                    }
                    }
                ]
            });
            DyyBase.ajax(sysApi.url_pipe_room(),{'jsonBean.pageCount':1000},function(dataset){
                var json = DyyBase.getSelect(dataset);
                $pipe_room_select = $('#JQ_pipe_room_select').select3({
                    title: '场站阀室',
                    data: json,
                    server: true,
                    serverPath: sysApi.url_pipe_room()
                });
            },{async:false});
        }
    }

    function loadSegment(){
        if(DTSEGMENT){
            DTSEGMENT.draw();
        }else{
            DTSEGMENT = $segment_table.DataTable({
                'language': {
                    'paginate': {
                        'next': '下一页',
                        'previous': '上一页'
                    },
                    'info': '本次检索共 _TOTAL_ 条，每页显示 10 条，共 _PAGES_ 页',
                    'zeroRecords': DyyBase.table_empty(),
                    'infoEmpty': ''
                },
                'autoWidth': false,
                'order': [],
                'serverSide': true,
                'pageLength': 10,
                'ordering': false,
                'processing': false,
                'searching': false,
                'lengthChange': false,
                'ajax': function (data, callback) {
                    var param = filter.getSegmentFilter(data);
                    DyyBase.ajax(sysApi.url_segment_list(), param, function (dataset) {
                        var returnData = {};
                        returnData.draw = data.draw;
                        returnData.recordsTotal = dataset.result.total;
                        returnData.recordsFiltered = dataset.result.total;
                        returnData.data = DyyBase.clearNull(dataset.result.list);
                        callback(returnData);
                    });
                },
                'drawCallback': function () {
                },
                'columns': [
                    {
                        data: 'id', render: function (data) {
                        return '<i class="zy-checkbox" data-id="' + data + '" title="选中"></i>';
                    }
                    },
                    {
                        data: 'pipeLineName', render: function (data) {
                        return '<span title="' + data + '">' + data + '</span>';
                    }
                    },
                    {
                        data: 'showName', render: function (data) {
                        return '<span title="' + data + '">' + data + '</span>';
                    }
                    },
                    {
                        data: 'fromName', render: function (data) {
                        return '<span title="' + data + '">' + data + '</span>';
                    }
                    },
                    {
                        data: 'toName', render: function (data) {
                        return '<span title="' + data + '">' + data + '</span>';
                    }
                    },
                    {
                        data: 'dataStated', render: function (data) {
                        if(data == '20'){
                            return '<span title="' + data + '">已发布</span>';
                        }else{
                            return '<span title="' + data + '">未发布</span>';
                        }
                    }
                    },
                    {
                        data: 'state', render: function (data,type,row) {
                        if(data == '0'){
                            return '<i data-id="'+row.id+'" data-state="'+data+'" class="zy-switch-sys"></i>';
                        }else{
                            return '<i data-id="'+row.id+'" data-state="'+data+'" class="zy-switch-sys off"></i>';
                        }
                    }
                    },
                    {
                        data: 'id', render: function (data) {
                        return '<i data-id="'+data+'" class="zy-record-add-icon" title="编辑"></i>&nbsp;&nbsp;&nbsp;<i data-id="'+data+'" class="zy-list-icon-delete" title="删除"></i>';
                    }
                    }
                ]
            });
        }
        $segment_pipe.reload();
        $segment_pipe_edit.reload();
    }
    /*** 加载列表 end ***/


    /**
     * 验证s重复性
     * @param options
     * @param input
     * @returns {boolean}
     */
    function verifyRepeat(options,input){
        var mode = false;
        var defaults = {
            id: '',
            name: '',
            abridge: '',
            type: ''
        };
        var settings = $.extend(defaults,options);
        DyyBase.ajax(sysApi.url_verify_repeat(),settings,function(dataset){
            if(dataset.bool){
                mode = dataset.result;
            }
        },{'async':false});
        if(mode){
            input.attr('data-repeat','true');
        }else{
            input.attr('data-repeat','false');
        }
        return mode;
    }


    /*** 场站阀室操作 start ***/
    // 查询
    $('#JQ_search_room').click(function () {
        if(DTROOM){
            DTROOM.draw();
        }
    });
    // 场站阀室列表 - 开/关
    $room_table.on('click','i.zy-switch-sys',function(event){
        var $this = $(this);
        var id = $this.attr('data-id'), state = $this.attr('data-state');
        state = state == '0' ? '1' : '0';

        DyyBase.ajax(sysApi.url_room_switch(),{ids:id,status:state},function(dataset){
            if(dataset.bool){
                $this.toggleClass('off');
                $this.attr('data-state',state);
            }
        });

        event.stopPropagation();
        return false;
    });
    // 场站阀室列表 - 删除
    $room_table.on('click','i.zy-list-icon-delete',function(event){
        var $this = $(this);
        var id = $this.attr('data-id');
        $this.MSG({
            type: 'confirm',
            tag: 'no',
            height: 230,
            content: '您确认要删除此场站阀室?',
            yesBtnTxt: '确认',
            yesBtnAct: function(){
                DyyBase.ajax(sysApi.url_room_delete(),{ids:id},function(dataset){
                    if(dataset.bool){
                        $this.MSG({
                            type: 'success',
                            content: dataset.result,
                            yesBtnAct: function(){
                                if(DTROOM){
                                    DTROOM.draw();
                                }
                            }
                        });
                    }
                });
            }
        });
        event.stopPropagation();
        return false;
    });
    // 场站阀室列表 - 批量删除
    $('#JQ_room_delete').click(function(){
        var $this = $(this);
        var param = filter.getRoomIds();
        if(param.length > 0){
            $this.MSG({
                type: 'confirm',
                tag: 'no',
                height: 230,
                content: '您确认要删除此选中的场站阀室?',
                yesBtnTxt: '确认',
                yesBtnAct: function(){
                    DyyBase.ajax(sysApi.url_room_delete(),param,function(dataset){
                        if(dataset.bool){
                            $this.MSG({
                                type: 'success',
                                content: dataset.result,
                                yesBtnAct: function(){
                                    if(DTROOM){
                                        DTROOM.draw();
                                    }
                                }
                            });
                        }
                    });
                }
            });
        }else{
            $this.MSG({
                content: '请选择您要删除的场站阀室!'
            });
        }
    });
    // 场站阀室列表 - 停用
    $('#JQ_room_disabled').click(function(){
        var $this = $(this);
        var param = filter.getRoomIds();
        if(param.length > 0){
            param.push({name:'status',value:'1'});
            $this.MSG({
                type: 'confirm',
                height: 230,
                content: '您确认要停用此选中的场站阀室?',
                yesBtnTxt: '确认',
                yesBtnAct: function(){
                    DyyBase.ajax(sysApi.url_room_switch(),param,function(dataset){
                        if(dataset.bool){
                            $this.MSG({
                                type: 'success',
                                content: dataset.result,
                                yesBtnAct: function(){
                                    if(DTROOM){
                                        DTROOM.draw();
                                    }
                                }
                            });
                        }
                    });
                }
            });
        }else{
            $this.MSG({
                content: '请选择您要停用的场站阀室!'
            });
        }
    });
    // 场站阀室列表 - 启用
    $('#JQ_room_usable').click(function(){
        var $this = $(this);
        var param = filter.getRoomIds();
        if(param.length > 0){
            param.push({name:'status',value:'0'});
            $this.MSG({
                type: 'confirm',
                height: 230,
                content: '您确认要启用此选中的场站阀室?',
                yesBtnTxt: '确认',
                yesBtnAct: function(){
                    DyyBase.ajax(sysApi.url_room_switch(),param,function(dataset){
                        if(dataset.bool){
                            $this.MSG({
                                type: 'success',
                                content: dataset.result,
                                yesBtnAct: function(){
                                    if(DTROOM){
                                        DTROOM.draw();
                                    }
                                }
                            });
                        }
                    });
                }
            });
        }else{
            $this.MSG({
                content: '请选择您要启用的场站阀室!'
            });
        }
    });
    // 场站阀室列表 - 发布
    $('#JQ_room_release').click(function(){
        var $this = $(this);
        var param = filter.getRoomIds();
        if(param.length > 0){
            $this.MSG({
                type: 'confirm',
                height: 230,
                content: '您确认要发布此选中的场站阀室?',
                yesBtnTxt: '确认',
                yesBtnAct: function(){
                    DyyBase.ajax(sysApi.url_room_release(),param,function(dataset){
                        if(dataset.bool){
                            $this.MSG({
                                type: 'success',
                                content: dataset.result,
                                yesBtnAct: function(){
                                    if(DTROOM){
                                        DTROOM.draw();
                                    }
                                }
                            });
                        }
                    });
                }
            });
        }else{
            $this.MSG({
                content: '请选择您要发布的场站阀室!'
            });
        }
    });
    // 新建
    $('#JQ_room_create').click(function(){
        var wind = $(this).WIND({
            width: 750,
            height: 400,
            title: '新建场站阀室',
            actionBox: 'div.room-box',
            closeBtn: 'i.room-close',
            yesBtn: 'JQ_action_room_yes_btn',
            noBtn: 'JQ_action_room_no_btn',
            yesBtnAct: function(){
                roomAction(wind.clear,null,[$room_name_edit,$room_code_edit]);
            },
            resetForm: $room_form
        });
    });
    // 编辑
    $room_table.on('click','i.zy-record-add-icon',function(){
        var $this = $(this);
        var $tr = $this.parent('td').parent('tr');
        var data = DTROOM.row($tr).data();
        if(data){
            $('#JQ_room_id').val(data.id);
            $room_name_edit.val(data.showName);
            $room_code_edit.val(data.abridge);
            $room_type_edit.fit(data.typeId);

            var wind = $this.WIND({
                width: 750,
                height: 400,
                title: '编辑场站阀室',
                actionBox: 'div.room-box',
                closeBtn: 'i.room-close',
                yesBtn: 'JQ_action_room_yes_btn',
                noBtn: 'JQ_action_room_no_btn',
                yesBtnAct: function(){
                    roomAction(wind.clear,data,[$room_name_edit,$room_code_edit]);
                },
                resetForm: $room_form
            });
        }
    });
    // 新建 & 编辑
    function roomAction(callback,data,inputs){
        var notRepeat = true;
        if(inputs.length){
            $.each(inputs,function(i,item){
                if(item.attr('data-repeat') == 'true'){
                    notRepeat = false;
                }
            });
        }

        var url, verify = $room_form.verify();
        if(notRepeat && verify){
            if(data){
                url = sysApi.url_room_update();
            }else{
                url = sysApi.url_room_create();
            }
            var param = filter.getRoom();
            if(param.mode){
                if(callback instanceof Function){
                    callback();
                }
                DyyBase.ajax(url,param,function(dataset){
                    if(dataset.bool){
                        $(this).MSG({
                            type: 'success',
                            content: dataset.result,
                            yesBtnAct: function(){
                                if(DTROOM){
                                    DTROOM.draw();
                                }
                            },
                            closeBtnAct: function(){
                                if(DTROOM){
                                    DTROOM.draw();
                                }
                            }
                        });
                    }else{
                        $(this).MSG({
                            type: 'error',
                            content: dataset.result
                        });
                    }
                });
                $room_form.reset();
            }
        }
    }
    // 验证场站阀室重复性
    $room_name_edit.on('blur',function(){
        var $this = $(this);
        var v = $.trim($this.val());
        if(v){
            if(verifyRepeat({id:$('#JQ_room_id').val(),name:v,type:'valve'},$this)){
                $this.TIP({
                    content:'此场站阀室名称存在重复!',
                    scroll: false
                });
            }
        }
    });
    $room_code_edit.on('blur',function(){
        var $this = $(this);
        var v = $.trim($this.val());
        if(v){
            if(verifyRepeat({id:$('#JQ_room_id').val(),abridge:v,type:'valve'},$this)){
                $this.TIP({
                    content:'此场站阀室代号存在重复!',
                    scroll: false
                });
            }
        }
    });
    /*** 场站阀室操作 end ***/


    /*** 管道操作 start ***/
    // 查询
    $('#JQ_search_pipe').click(function () {
        if(DTPIPE){
            DTPIPE.draw();
        }
    });
    // 管道列表 - 开/关  启用 status = 0 停用 status = 1
    $pipe_table.on('click','i.zy-switch-sys',function(event){
        var $this = $(this);
        var id = $this.attr('data-id');
        var state = $this.attr('data-state');
        state = state == '0' ? '1' : '0';

        DyyBase.ajax(sysApi.url_pipe_switch(),{ids:id,status:state},function(dataset){
            if(dataset.bool){
                $this.toggleClass('off');
                $this.attr('data-state',state);
            }
        });

        event.stopPropagation();
        return false;
    });
    // 管道列表 - 删除
    $pipe_table.on('click','i.zy-list-icon-delete',function(event){
        var $this = $(this);
        var id = $this.attr('data-id');
        $this.MSG({
            type: 'confirm',
            height: 230,
            content: '您确认要删除此管道',
            yesBtnTxt: '确认',
            yesBtnAct: function(){
                DyyBase.ajax(sysApi.url_pipe_delete(),{ids:id},function(dataset){
                    if(dataset.bool){
                        $this.MSG({
                            type: 'success',
                            content: dataset.result,
                            yesBtnAct: function(){
                                if(DTPIPE){
                                    DTPIPE.draw();
                                }
                            }
                        });
                    }
                });
            }
        });
        event.stopPropagation();
        return false;
    });
    // 管道列表 - 批量删除
    $('#JQ_pipe_delete').click(function(){
        var $this = $(this);
        var param = filter.getPipeIds();
        if(param.length > 0){
            $this.MSG({
                type: 'confirm',
                tag: 'no',
                height: 230,
                content: '您确认要删除此选中的管道?',
                yesBtnTxt: '确认',
                yesBtnAct: function(){
                    DyyBase.ajax(sysApi.url_pipe_delete(),param,function(dataset){
                        if(dataset.bool){
                            $this.MSG({
                                type: 'success',
                                content: dataset.result,
                                yesBtnAct: function(){
                                    if(DTPIPE){
                                        DTPIPE.draw();
                                    }
                                }
                            });
                        }
                    });
                }
            });
        }else{
            $this.MSG({
                content: '请选择您要删除的管道!'
            });
        }
    });
    // 管道列表 - 停用
    $('#JQ_pipe_disabled').click(function(){
        var $this = $(this);
        var param = filter.getPipeIds();
        if(param.length > 0){
            param.push({name:'status',value:'1'});
            $this.MSG({
                type: 'confirm',
                height: 230,
                content: '您确认要停用此选中的管道?',
                yesBtnTxt: '确认',
                yesBtnAct: function(){
                    DyyBase.ajax(sysApi.url_pipe_switch(),param,function(dataset){
                        if(dataset.bool){
                            $this.MSG({
                                type: 'success',
                                content: dataset.result,
                                yesBtnAct: function(){
                                    if(DTPIPE){
                                        DTPIPE.draw();
                                    }
                                }
                            });
                        }
                    });
                }
            });
        }else{
            $this.MSG({
                content: '请选择您要停用的管道!'
            });
        }
    });
    // 管道列表 - 启用
    $('#JQ_pipe_usable').click(function(){
        var $this = $(this);
        var param = filter.getPipeIds();
        if(param.length > 0){
            param.push({name:'status',value:'0'});
            $this.MSG({
                type: 'confirm',
                height: 230,
                content: '您确认要启用此选中的管道?',
                yesBtnTxt: '确认',
                yesBtnAct: function(){
                    DyyBase.ajax(sysApi.url_pipe_switch(),param,function(dataset){
                        if(dataset.bool){
                            $this.MSG({
                                type: 'success',
                                content: dataset.result,
                                yesBtnAct: function(){
                                    if(DTPIPE){
                                        DTPIPE.draw();
                                    }
                                }
                            });
                        }
                    });
                }
            });
        }else{
            $this.MSG({
                content: '请选择您要启用的管道!'
            });
        }
    });
    // 管道列表 - 发布
    $('#JQ_pipe_release').click(function(){
        var $this = $(this);
        var param = filter.getPipeIds();
        if(param.length > 0){
            $this.MSG({
                type: 'confirm',
                height: 230,
                content: '您确认要发布此选中的管道?',
                yesBtnTxt: '确认',
                yesBtnAct: function(){
                    DyyBase.ajax(sysApi.url_pipe_release(),param,function(dataset){
                        if(dataset.bool){
                            $this.MSG({
                                type: 'success',
                                content: dataset.result,
                                yesBtnAct: function(){
                                    if(DTPIPE){
                                        DTPIPE.draw();
                                    }
                                }
                            });
                        }
                    });
                }
            });
        }else{
            $this.MSG({
                content: '请选择您要发布的管道!'
            });
        }
    });
    // 添加场站阀室
    $('#JQ_search_add_pipe').click(function(){
        var id = $pipe_room_select.val();
        var text = $pipe_room_select.val('text');
        if(id && text){
            var $tr = $pipe_room_table.find('tbody').find('tr');
            var mode = true;
            if($tr.length > 0){
                $tr.each(function(){
                    var $this_tr = $(this);
                    if($this_tr.attr('data-id') == id){
                        mode = false;
                    }
                });
            }
            if(mode){
                var tr = '<tr data-id="'+id+'"><td width="80%">'+text+'</td><td width="20%"><i title="删除" class="zy-list-icon-delete" data-id="'+id+'"></i></td></tr>';
                $pipe_room_table.find('tbody').append(tr);
            }else{
                $pipe_room_select.element.TIP({content: '此场站阀室已被添加!'});
            }
        }else{
            $pipe_room_select.element.TIP({content: '请选择要添加的场站阀室!'});
        }
    });
    $pipe_room_table.on('click','i.zy-list-icon-delete',function(){
        var $this = $(this);
        $this.parent('td').parent('tr').remove();
    });
    // 查看沿线场站阀室
    $pipe_table.on('click','i.zy-view-icon',function(){
        var $this = $(this);
        var id = $this.attr('data-id');
        var tr = '';
        if(id){
            DyyBase.ajax(sysApi.url_pipe_all_room(),{pipeLineId:id,type:0},function(dataset){
                if(dataset.bool){
                    if(dataset.result && dataset.result.length > 0){
                        for(var i = 0, len = dataset.result.length; i < len; i++){
                            tr += '<tr><td>'+dataset.result[i].elementName+'</td></tr>';
                        }
                    }
                }
            },{async:false});
        }
        $('#JQ_pipe_all_room').empty().append(tr);

        $this.WIND({
            width: 400,
            height: 500,
            title: '沿线场站阀室',
            actionBox: 'div.pipe-room',
            closeBtn: 'i.pipe-room-close'
        });
    });
    // 新建
    $('#JQ_pipe_create').click(function(){
        var wind = $(this).WIND({
            width: 750,
            height: 620,
            title: '新建',
            actionBox: 'div.pipe-box',
            closeBtn: 'i.pipe-close',
            yesBtn: 'JQ_action_pipe_yes_btn',
            noBtn: 'JQ_action_pipe_no_btn',
            yesBtnAct: function(){
                pipeAction(wind.clear,null,[$pipe_name_edit,$pipe_code_edit]);
            },
            resetForm: $pipe_form
        });
    });
    // 编辑
    $pipe_table.on('click','i.zy-record-add-icon',function(){
        var $this = $(this);
        var $tr = $this.parent('td').parent('tr');
        var data = DTPIPE.row($tr).data();
        var tr = '';
        if(data){
            $('#JQ_pipe_id').val(data.id);
            $pipe_name_edit.val(data.showName);
            $pipe_code_edit.val(data.abridge);

            DyyBase.ajax(sysApi.url_pipe_all_room(),{pipeLineId:data.id,type:0},function(dataset){
                if(dataset.bool){
                    if(dataset.result && dataset.result.length > 0){
                        for(var i = 0, len = dataset.result.length; i < len; i++){
                            tr += '<tr data-id="'+dataset.result[i].elementId+'"><td width="80%">'+dataset.result[i].elementName+'</td><td width="20%"><i data-id="'+dataset.result[i].elementId+'" class="zy-list-icon-delete" title="删除"></i></td></tr>';
                        }
                    }
                    $pipe_room_table.find('tbody').append(tr);
                }
            },{async:false});

            var wind = $this.WIND({
                width: 750,
                height: 600,
                title: '编辑',
                actionBox: 'div.pipe-box',
                closeBtn: 'i.pipe-close',
                yesBtn: 'JQ_action_pipe_yes_btn',
                noBtn: 'JQ_action_pipe_no_btn',
                yesBtnAct: function(){
                    pipeAction(wind.clear,data,[$pipe_name_edit,$pipe_code_edit]);
                },
                resetForm: $pipe_form
            });
        }
    });
    // 新建 & 编辑
    function pipeAction(callback,data,inputs){
        var notRepeat = true;
        if(inputs.length){
            $.each(inputs,function(i,item){
                if(item.attr('data-repeat') == 'true'){
                    notRepeat = false;
                }
            });
        }

        var url, verify = $pipe_form.verify();
        if(notRepeat && verify){
            if(data){
                url = sysApi.url_pipe_edit();
            }else{
                url = sysApi.url_pipe_create();
            }
            var param = filter.getPipe();
            if(param.mode){
                if(callback instanceof Function){
                    callback();
                }
                DyyBase.ajax(url,DyyBase.convertToArr(param),function(dataset){
                    if(dataset.bool){
                        // 清空管道缓存 - start
                        Dyy.deleteStorage('lineData');
                        // 清空管道缓存 - end
                        $(this).MSG({
                            type: 'success',
                            content: dataset.result,
                            yesBtnAct: function(){
                                if(DTPIPE){
                                    DTPIPE.draw();
                                }
                            },
                            closeBtnAct: function(){
                                if(DTPIPE){
                                    DTPIPE.draw();
                                }
                            }
                        });
                    } else {
                        $(this).MSG({
                            type: 'error',
                            content: dataset.result
                        });
                    }
                });
                $pipe_form.reset();
            }
        }
    }
    // 重置
    $pipe_room_table.on('reset',function(){
        $pipe_room_table.find('tbody').empty();
    });
    // 分段标识
    $pipe_table.on('click','i.zy-edit-icon-txt',function(){
        var $this = $(this);
        var id = $this.attr('data-id');

        DyyBase.ajax(sysApi.url_pipe_all_room(),{pipeLineId:id},function(dataset){
            if(dataset.bool){
                var tr = '';
                for(var i = 0, len = dataset.result.length; i < len; i++){
                    if(dataset.result[i].isParticipationSegmen == 1){
                        tr += '<tr><td>'+dataset.result[i].elementName+'</td><td><i class="zy-switch-sys" data-state="1" data-id="'+dataset.result[i].id+'"></i></td></tr>';
                    }else{
                        tr += '<tr><td>'+dataset.result[i].elementName+'</td><td><i class="zy-switch-sys off" data-state="0" data-id="'+dataset.result[i].id+'"></i></td></tr>';
                    }
                }
                $pipe_sign_room.find('tbody').empty().append(tr);
            }
        });

        $this.WIND({
            width: 450,
            height: 500,
            title: '分段标识',
            actionBox: 'div.sign-room',
            closeBtn: 'i.sign-room-close'
        });
    });
    // 分段标识 开/关
    $pipe_sign_room.on('click','i.zy-switch-sys',function(){
        var $this = $(this);
        var state = $this.attr('data-state');
        var id = $this.attr('data-id');
        state = state == '1' ? '0' : '1';
        DyyBase.ajax(sysApi.url_pipe_room_switch(),{ids:id,status:state},function(dataset){
            if(dataset.bool){
                $this.toggleClass('off');
                $this.attr('data-state',state);
            }
        });
    });
    $pipe_name_edit.on('blur',function(){
        var $this = $(this);
        var v = $.trim($this.val());
        if(v){
            if(verifyRepeat({id:$('#JQ_pipe_id').val(),name:v,type:'line'},$this)){
                $this.TIP({
                    content:'此管道名称存在重复!',
                    scroll: false
                });
            }
        }
    });
    $pipe_code_edit.on('blur',function(){
        var $this = $(this);
        var v = $.trim($this.val());
        if(v){
            if(verifyRepeat({id:$('#JQ_pipe_id').val(),abridge:v,type:'line'},$this)){
                $this.TIP({
                    content:'此管道代号存在重复!',
                    scroll: false
                });
            }
        }
    });
    /*** 管道操作 end ***/


    /*** 管段操作 start ***/
    // 查询
    $('#JQ_search_segment').click(function () {
        if(DTSEGMENT){
            DTSEGMENT.draw();
        }
    });
    // 管段列表 - 开/关
    $segment_table.on('click','i.zy-switch-sys',function(event){
        var $this = $(this);
        var id = $this.attr('data-id'), state = $this.attr('data-state');
        state = state == '0' ? '1' : '0';

        DyyBase.ajax(sysApi.url_segment_switch(),{ids:id,status:state},function(dataset){
            if(dataset.bool){
                $this.toggleClass('off');
            }
        });

        event.stopPropagation();
        return false;
    });
    // 管段列表 - 删除
    $segment_table.on('click','i.zy-list-icon-delete',function(event){
        var $this = $(this);
        var id = $this.attr('data-id');
        $this.MSG({
            type: 'confirm',
            height: 230,
            content: '您确认要删除此管段?',
            yesBtnTxt: '确认',
            yesBtnAct: function(){
                DyyBase.ajax(sysApi.url_segment_delete(),{ids:id},function(dataset){
                    if(dataset.bool){
                        $this.MSG({
                            type: 'success',
                            content: dataset.result,
                            yesBtnAct: function(){
                                if(DTSEGMENT){
                                    DTSEGMENT.draw();
                                }
                            }
                        });
                    }
                });
            }
        });
        event.stopPropagation();
        return false;
    });
    // 管段列表 - 批量删除
    $('#JQ_segment_delete').click(function(){
        var $this = $(this);
        var param = filter.getSegmentIds();
        if(param.length > 0){
            $this.MSG({
                type: 'confirm',
                tag: 'no',
                height: 230,
                content: '您确认要删除此选中的管段?',
                yesBtnTxt: '确认',
                yesBtnAct: function(){
                    DyyBase.ajax(sysApi.url_segment_delete(),param,function(dataset){
                        if(dataset.bool){
                            $this.MSG({
                                type: 'success',
                                content: dataset.result,
                                yesBtnAct: function(){
                                    if(DTSEGMENT){
                                        DTSEGMENT.draw();
                                    }
                                }
                            });
                        }
                    });
                }
            });
        }else{
            $this.MSG({
                content: '请选择您要删除的管段!'
            });
        }
    });
    // 管段列表 - 停用
    $('#JQ_segment_disabled').click(function(){
        var $this = $(this);
        var param = filter.getSegmentIds();
        if(param.length > 0){
            param.push({name:'status',value:'1'});
            $this.MSG({
                type: 'confirm',
                height: 230,
                content: '您确认要停用此选中的管段?',
                yesBtnTxt: '确认',
                yesBtnAct: function(){
                    DyyBase.ajax(sysApi.url_segment_switch(),param,function(dataset){
                        if(dataset.bool){
                            $this.MSG({
                                type: 'success',
                                content: dataset.result,
                                yesBtnAct: function(){
                                    if(DTSEGMENT){
                                        DTSEGMENT.draw();
                                    }
                                }
                            });
                        }
                    });
                }
            });
        }else{
            $this.MSG({
                content: '请选择您要停用的管段!'
            });
        }
    });
    // 管段列表 - 启用
    $('#JQ_segment_usable').click(function(){
        var $this = $(this);
        var param = filter.getSegmentIds();
        if(param.length > 0){
            param.push({name:'status',value:'0'});
            $this.MSG({
                type: 'confirm',
                height: 230,
                content: '您确认要启用此选中的管段?',
                yesBtnTxt: '确认',
                yesBtnAct: function(){
                    DyyBase.ajax(sysApi.url_segment_switch(),param,function(dataset){
                        if(dataset.bool){
                            $this.MSG({
                                type: 'success',
                                content: dataset.result,
                                yesBtnAct: function(){
                                    if(DTSEGMENT){
                                        DTSEGMENT.draw();
                                    }
                                }
                            });
                        }
                    });
                }
            });
        }else{
            $this.MSG({
                content: '请选择您要启用的管段!'
            });
        }
    });
    // 管段列表 - 发布
    $('#JQ_segment_release').click(function(){
        var $this = $(this);
        var param = filter.getSegmentIds();
        if(param.length > 0){
            $this.MSG({
                type: 'confirm',
                height: 230,
                content: '您确认要发布此选中的管段?',
                yesBtnTxt: '确认',
                yesBtnAct: function(){
                    DyyBase.ajax(sysApi.url_segment_release(),param,function(dataset){
                        if(dataset.bool){
                            $this.MSG({
                                type: 'success',
                                content: dataset.result,
                                yesBtnAct: function(){
                                    if(DTSEGMENT){
                                        DTSEGMENT.draw();
                                    }
                                }
                            });
                        }
                    });
                }
            });
        }else{
            $this.MSG({
                content: '请选择您要发布的管段!'
            });
        }
    });
    // 新建
    $('#JQ_segment_create').click(function(){
        var wind = $(this).WIND({
            width: 800,
            height: 430,
            title: '新建',
            actionBox: 'div.segment-box',
            closeBtn: 'i.segment-close',
            yesBtn: 'JQ_action_segment_yes_btn',
            noBtn: 'JQ_action_segment_no_btn',
            yesBtnAct: function(){
                segmentAction(wind.clear,null,[$segment_name_edit,$segment_code_edit]);
            },
            resetForm: $segment_form
        });
    });
    // 编辑
    $segment_table.on('click','i.zy-record-add-icon',function(){
        var $this = $(this);
        var $tr = $this.parent('td').parent('tr');
        var data = DTSEGMENT.row($tr).data();
        if(data){
            $('#JQ_segment_id').val(data.id);
            $segment_pipe_edit.fit(data.pipeLineId);
            $segment_name_edit.val(data.showName);
            $segment_code_edit.val(data.abridge);
            $segment_begin.asset([{id:data.fromPipeValveroomId,text:data.fromName}]);
            $segment_end.asset([{id:data.toPipeValveroomId,text:data.toName}]);

            var wind = $this.WIND({
                width: 800,
                height: 430,
                title: '编辑',
                actionBox: 'div.segment-box',
                closeBtn: 'i.segment-close',
                yesBtn: 'JQ_action_segment_yes_btn',
                noBtn: 'JQ_action_segment_no_btn',
                yesBtnAct: function(){
                    segmentAction(wind.clear,data,[$segment_name_edit,$segment_code_edit]);
                },
                resetForm: $segment_form
            });
        }
    });
    // 新建 & 编辑
    function segmentAction(callback,data,inputs){
        var notRepeat = true;
        if(inputs.length){
            $.each(inputs,function(i,item){
                if(item.attr('data-repeat') == 'true'){
                    notRepeat = false;
                }
            });
        }

        var url, verify = $segment_form.verify();
        if(notRepeat && verify){
            if(data){
                url = sysApi.url_segment_edit();
            }else{
                url = sysApi.url_segment_create();
            }
            var param = filter.getSegmentFilter2();
            if(param.mode){
                if(callback instanceof Function){
                    callback();
                }
                DyyBase.ajax(url,param,function(dataset){
                    if(dataset.bool){
                        $(this).MSG({
                            type: 'success',
                            content: dataset.result,
                            yesBtnAct: function(){
                                if(DTSEGMENT){
                                    DTSEGMENT.draw();
                                }
                            },
                            closeBtnAct: function(){
                                if(DTSEGMENT){
                                    DTSEGMENT.draw();
                                }
                            }
                        });
                    }else{
                        $(this).MSG({
                            type: 'error',
                            content: dataset.result
                        });
                    }
                });
                $segment_form.reset();
            }
        }
    }
    $segment_name_edit.on('blur',function(){
        var $this = $(this);
        var v = $.trim($this.val());
        if(v){
            if(verifyRepeat({id:$('#JQ_segment_id').val(),name:v,type:'segment'},$this)){
                $this.TIP({
                    content:'此管段名称存在重复!',
                    scroll: false
                });
            }
        }
    });
    $segment_code_edit.on('blur',function(){
        var $this = $(this);
        var v = $.trim($this.val());
        if(v){
            if(verifyRepeat({id:$('#JQ_segment_id').val(),abridge:v,type:'segment'},$this)){
                $this.TIP({
                    content:'此管段代号存在重复!',
                    scroll: false
                });
            }
        }
    });
    /*** 管段操作 end ***/


    // 记忆切换选项卡 - start
    var $tab_li = $('div.zy-tab-head').find('li');
    var $tab_div = $('div.zy-div-tab');
    function changeTab(tab){
        $tab_li.removeClass('active');
        $tab_div.addClass('hidden');

        $('#'+tab).removeClass('hidden');
        $('li[data-tab="'+tab+'"]').addClass('active');

        switch (tab){
            case 'JQ_valve_room':
                loadRoom();
                break;
            case 'JQ_pipe_line':
                loadPipe();
                break;
            case 'JQ_pipe_segment':
                loadSegment();
                break;
            default:
                break;
        }

        Dyy.setStorage('pipeBaseTab',tab);
    }

    $tab_li.click(function () {
        var $this = $(this);
        changeTab($this.attr('data-tab'));
    });

    var tab = Dyy.getStorage('pipeBaseTab');
    if(tab){
        changeTab(tab);
    }else{
        changeTab('JQ_valve_room');
    }
    // 记忆切换选项卡 - end

})($, window, document);